<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">

    <link rel="stylesheet" href="../layui/css/layui.css">
    <script src="../layui/layui.js"></script>
    <script src="../scripts/jquery.min.js"></script>
    <script src="../js/jquery-form.js"></script>

    <style type="text/css">
        .for_img_upload{

        }
    </style>

    <title>图标信息修改</title>
    <style>
        body{padding: 10px;}
        .change_size{
            height: 100px;
        }
    </style>
</head>

<body>

<input type="hidden" id="flag_manager" value=<%=session.getAttribute("flag_manager")%> />


<input type="hidden" id="flag_edit" value="no" />

<form  class="layui-form layui-form-pane1" id="subform" method="post">

    <input type="hidden" name="icon_id" id="icon_id" value=${param.icon_id} />

    <div class="layui-form-item">
        <label class="layui-form-label">标识名称</label>
        <div class="layui-input-block">
            <input type="text" id="icon_name" name="icon_name" lay-verify="required|title"  placeholder="请输入标题" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">图标类型</label>
        <div class="layui-input-block">
            <select id="icon_class" name="icon_class" lay-filter="adminRole" >
                <option value="">请选择类型</option>
                <option value="禁令标志">禁令标志</option>
                <option value="警告标志">警告标志</option>
                <option value="指示标志">指示标志</option>
                <option value="指路标志">指路标志</option>
                <option value="交通手势信号">交通手势信号</option>
                <option value="旅游区标志">旅游区标志</option>
                <option value="道路施工安全标志">道路施工安全标志</option>
                <option value="辅助标志">辅助标志</option>
                <option value="其它标志">其它标志</option>
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">图标图片</label>
        <div class="layui-input-block">
            <input type="text" id="icon_img" name="icon_img" lay-verify="required|title"  readonly="readonly" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">标识描述</label>
        <div class="layui-input-block">
            <textarea id="icon_des" name="icon_des" placeholder="请输入内容或上传文件（优先选择文件）" class="layui-textarea change_size"></textarea>
        </div>
    </div>

    <div>
        <div style="float: left;">
            <div class="layui-form-item">
                <label class="layui-form-label">传文修改</label>
                <div class="layui-input-block">
                    <input type="file" name="file_content" id="file_content" accept="text/plain" />
                </div>
            </div>
        </div>

        <div style="float: right;padding-right: 50px;">
            <div class="layui-form-item">
                <button type="button" class="layui-btn for_img_upload" id="img_update_btn" >
                    <i class="layui-icon">&#xe67c;</i>修改图片
                </button>
                <div class="layui-upload-list">
                    <img class="layui-upload-img for_img_upload" id="img_update" width="110" height="110">
                </div>
            </div>
        </div>

    </div>



</form>
<br>
<div style="float: left">
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" id="add_btn" onclick="to_submit()" >立即修改</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</div>


<script>
    //加载layui信息
    layui.use('form', function(){
        var form = layui.form;
        //layui日期选择
        layui.use('laydate', function(){
            var laydate = layui.laydate;

            //执行一个laydate实例
            laydate.render({
                elem: '#createTime', //指定元素
                value: new Date()
            });
        });
    });

    var layer;
    layui.use('layer', function(){
        layer = layui.layer;

    })

    window.onload=function (){
        $.ajax({
            url:"${pageContext.request.contextPath}/icon/icon_table_edit_init.do",
            data:{
                "icon_id":$('#icon_id').val()
            },
            success:function (data,status){
                if(status=="success"){
                    $("#icon_name").val(data.icon_name);
                    $("#icon_des").val(data.icon_des);
                    $("#icon_img").val(data.icon_img);
                    var path="${pageContext.request.contextPath}/img_artificial/"+"icon_img/"+data.icon_img;
                    var select = 'dd[lay-value=' + data.icon_class + ']';
                    $('#icon_class').siblings("div.layui-form-select").find('dl').find(select).click();
                    $("#img_update").attr("src",path);
                }
            }
        })
    }

    function to_submit(){
        var icon_name=$("#icon_name").val();
        var icon_class=$("#icon_class").val();

        if(icon_name==""){
            layer.msg("标题不能为空");
            return ;
        }
        if(icon_class==""){
            layer.msg("您还没有选择类型");
            return ;
        }
        if($("#flag_manager").val()!="null"){
            ajaxFile("${pageContext.request.contextPath}/icon/icon_table_edit.do");
        }else{
            layer.msg("修改失败，您不是管理员");
        }

    }
    function ajaxFile(url){

        $("#subform").ajaxSubmit({
            url:url,
            type:"post",
            enctype:'multipart/form-data',
            success:function(data,status){
                if(status=="success") {
                    $("#flag_edit").val("yes");
                    $("#icon_des").val(data.str);
                    layer.msg("数据修改成功", {icon: 1});
                }
            }
        })
    }

    layui.use('upload', function(){
        var upload = layui.upload;

        //执行实例
        var uploadInst = upload.render({
            elem: '#img_update' //绑定元素
            ,url: '${pageContext.request.contextPath}/icon/icon_table_edit_upload_img.do' //上传接口
            ,data:{
                "icon_id":$("#icon_id").val()
            }
            ,accept:"images"
            ,acceptMine:"images/*"
            ,auto:false
            ,bindAction:"#img_update_btn"
            ,choose:function (obj){
                obj.preview(function(index,file,result){
                    $('#img_update').attr('src', result);
                });
            }
            ,done: function(res){
                //上传完毕回调
                if(res.data!="fail") {
                    $("#flag_edit").val("yes");
                    $("#icon_img").val(res.data);
                    layer.msg("图片修改成功");
                }else{
                    layer.msg("操作失败，您不是管理员");
                }
            }
            ,error: function(){
                //请求异常回调
                layer.msg("上传失败");
            }
        });
    });


</script>

</body>
</html>
